#define  _CRT_SECURE_NO_WARNINGS 1
#include"string.h"
namespace Z {

	//string::string()
	//	:_size(0)
	//	, _capacity(0)
	//	, _str(new char [1] {'\0'})
	//{

	//}
	string::string(const char* str)
		:_size(strlen(str))
	{
		_capacity = _size;
		_str = new char[_size + 1];
		strcpy(_str, str);
	}
	string::~string() {
		delete[]_str;
		_str = nullptr;
		_size = 0;
		_capacity = 0;


	}

	void string::reserve(int n)
	{
		if (n > _capacity) {
			char* tmp = new char[n + 1];
			strcpy(tmp, _str);
			delete(_str);
			_str = tmp;
			_capacity = n;



		}



	}
	void string::push_back(char ch) {
		if (_size == _capacity) {
			reserve(_capacity==0?4:_size * 2);
		}
		_str[_size] = ch;
		_size++;
		

	}
	void string::append(const char* str) {
		int newcapacity;
		if (_size + strlen(str) > _capacity) {
			 newcapacity = _capacity * 2;



		}
		if (newcapacity < _size + strlen(str)) {
			newcapacity = _size + strlen(str);
		}
		reserve(newcapacity);
		strcpy(_str + _size, str);
		_size = _size + strlen(str);
	}
	string& string::operator+=(char ch) {
		push_back(ch);
		return *this;
	}
	string& string::operator+=(const char* str) {

		append(str);
		return *this;
	}
	
}